package com.com.designpatterns.composite;

import java.util.*;

/**
 * Created by User on 17/09/2014.
 */
public class Boss extends Employee {

    Vector<Employee> _employees;

    public Boss(String _name, float _salary) {
        super(_name, _salary);
        leaf = false;
        _employees = new Vector<>();
    }

    public Boss(Employee _parent, String _name, float _salary) {
        super(_parent, _name, _salary);
        leaf = false;
        _employees = new Vector<>();
    }

    public Boss(Employee employee){
        super(employee.getName(), employee.getSalary());
        leaf = false;
        _employees = new Vector<>();
    }

    @Override
    public boolean addEmployee(Employee e) throws NoSuchElementException {
        _employees.add(e);
        return true;
    }

    @Override
    public boolean remove(Employee e) throws NoSuchElementException {
        boolean removed= _employees.removeElement(e);
        return removed;
    }

    @Override
    public Enumeration<Employee> subordinates(){
        return _employees.elements();
    }

    @Override
    public double getSalaries(){
        double sum = 0, subordinateSalary = 0;
        sum = salary;
        subordinateSalary = _employees.stream().mapToDouble(e->e.getSalary()).sum();

        return sum + subordinateSalary;
    }

    public static void main(String[] args) {
        List l = new ArrayList<Integer>();
        l.add(1);l.add(2);l.add(3);l.add(4);

        l.stream().forEach(n -> System.out.println(n));
        int sum = l.stream().mapToInt((n) -> (Integer)n).sum();
        System.out.println("sum = " + sum);
    }




}
